package com.secondhand.project.service.impl;

import cn.hutool.core.date.DateUtil;
import com.secondhand.common.utils.SecurityUtils;
import com.secondhand.project.domain.ChatInfo;
import com.secondhand.project.mapper.ChatInfoMapper;
import com.secondhand.project.service.IChatInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChatInfoServiceImpl implements IChatInfoService {
    @Autowired
    private ChatInfoMapper chatInfoMapper;

    public Long selectUnReadChatNum(Long userId, Long chatUserId) {
        return chatInfoMapper.selectUnReadChatNum(userId, chatUserId);
    }

    public List<ChatInfo> selectUserChat(Long chatUserId) {
        Long userId = SecurityUtils.getUserId();
        return chatInfoMapper.selectUserChat(userId, chatUserId);
    }

    public void updateRead(Long chatUserId) {
        Long userId = SecurityUtils.getUserId();
        chatInfoMapper.updateRead(userId, chatUserId);
    }

    @Override
    public ChatInfo selectChatInfoById(Long id) {
        return chatInfoMapper.selectChatInfoById(id);
    }

    @Override
    public List<ChatInfo> selectChatInfoList(ChatInfo chatInfo) {
        return chatInfoMapper.selectChatInfoList(chatInfo);
    }

    @Override
    public int insertChatInfo(ChatInfo chatInfo) {
        chatInfo.setTime(DateUtil.now());
        return chatInfoMapper.insertChatInfo(chatInfo);
    }

    @Override
    public int updateChatInfo(ChatInfo chatInfo) {
        return chatInfoMapper.updateChatInfo(chatInfo);
    }

    @Override
    public int deleteChatInfoByIds(Long[] ids) {
        return chatInfoMapper.deleteChatInfoByIds(ids);
    }

    @Override
    public int deleteChatInfoById(Long id) {
        return chatInfoMapper.deleteChatInfoById(id);
    }
}
